package com.mojo.tree.traverse;

import com.mojo.tree.ChainBinaryTree;

/**
 * 树的前序遍历算法实现
 *
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2022, 广州九尾信息科技有限公司
 * @date 2022/9/2 11:14
 */
public class OrderTraverse {
    public static void preOrderTraverse(ChainBinaryTree binaryTree) {
        if (binaryTree == null) {
            return;
        }
        //遍历左子树
        preOrderTraverse(binaryTree.getlChild());
        preOrderTraverse(binaryTree.getrChild());
        System.out.printf("%s\t", binaryTree.getData());

    }

    public static void main(String[] args) {
        ChainBinaryTree[] trees = new ChainBinaryTree[10];
        for (int i = 0; i < 10; i++) {
            trees[i] = new ChainBinaryTree(null, null, i + 1);
        }
        ChainBinaryTree t1 = new ChainBinaryTree(null, null, 1);
        ChainBinaryTree t2 = new ChainBinaryTree(null, null, 2);
        ChainBinaryTree t3 = new ChainBinaryTree(t1, t2, 3);
        ChainBinaryTree t4 = new ChainBinaryTree(null, null, 4);
        ChainBinaryTree t5 = new ChainBinaryTree(null, null, 5);
        ChainBinaryTree t6 = new ChainBinaryTree(t4, t5, 6);
        ChainBinaryTree t7 = new ChainBinaryTree(t3, t6, 7);
        ChainBinaryTree t8 = new ChainBinaryTree(null, null, 8);
        ChainBinaryTree t9 = new ChainBinaryTree(t8, null, 9);
        ChainBinaryTree t10 = new ChainBinaryTree(t7, t9, 10);
        preOrderTraverse(t10);
    }

    /**
     * 创建二叉树
     *
     * @param binaryTree 二叉树
     * @param data       数据
     */
    public void createBiTree(ChainBinaryTree binaryTree, Object data) {

    }
}
